package com.tang.algorithm.binaryserch;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/7/4 20:38
 */
public class LeetCode1351 {
    public int countNegatives(int[][] grid) {
        int res = 0;
        for (int i = 0; i <grid.length ; i++) {
            int left = 0,right = grid[0].length-1;
            if(grid[i][right]>0){
                continue;
            }
            while (left<=right){
                int mid = (left+right)>>>1;
                if(grid[i][left]<0){
                    left++;
                    res++;
                }else if(grid[i][mid]<=0){
                    left++;
                }else if(grid[i][mid]>=0){
                    left=mid+1;
                }
            }
        }
        return res;
    }
}
